package it.eng.area118.mdocommon.android.sound;

import it.eng.area118.mdocommon.android.util.AndroidApplicationContext;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;

public class AndroidSound implements Sound {

	private MediaPlayer mPlayer;

	private int count = 0;

	@Override
	public void playSound(int soundFile) {
		mPlayer = MediaPlayer.create(AndroidApplicationContext.getInstance()
				.getApplicationContext(), soundFile);
		mPlayer.start();
	}

	@Override
	public void playSound(int soundFile, final int times) {
		count = 0;
		mPlayer = MediaPlayer.create(AndroidApplicationContext.getInstance()
				.getApplicationContext(), soundFile);
		mPlayer.start();
		mPlayer.setOnCompletionListener(new OnCompletionListener() {

			@Override
			public void onCompletion(MediaPlayer arg0) {
				count++;
				if (count < times) {
					mPlayer.start();
				}

			}
		});

	}
}
